package org.dromara.tearoom.controller;

import cn.hutool.core.util.ObjectUtil;
import lombok.RequiredArgsConstructor;
import org.dromara.common.core.domain.R;
import org.dromara.common.core.validate.AddGroup;
import org.dromara.common.idempotent.annotation.RepeatSubmit;
import org.dromara.common.mybatis.core.page.PageQuery;
import org.dromara.common.mybatis.core.page.TableDataInfo;
import org.dromara.common.web.core.BaseController;
import org.dromara.tearoom.domain.bo.TerCleanerLogBo;
import org.dromara.tearoom.domain.bo.TerOrderBo;
import org.dromara.tearoom.domain.bo.TerUserSubscriptionBo;
import org.dromara.tearoom.domain.vo.TerOrderVo;
import org.dromara.tearoom.service.ITerCleanOrderService;
import org.dromara.tearoom.service.ITerCleanerLogService;
import org.dromara.tearoom.service.ITerUserSubscriptionService;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

/**
 * 保洁订单查询
 * @author CKJ
 * @description: TODO
 * @date 2025/4/18 10:53
 */
@Validated
@RequiredArgsConstructor
@RestController
@RequestMapping("/cleaner")
public class TerCleanOrderController extends BaseController {

    private final ITerCleanOrderService terCleanOrderService;

    private final ITerCleanerLogService terCleanerLogService;

    private final ITerUserSubscriptionService terUserSubscriptionService;

    /**
     * 获取保洁订单数据
     * @param bo
     * @param pageQuery
     * @return
     */
    @GetMapping("/list")
    public TableDataInfo<TerOrderVo> getList(TerOrderBo bo, PageQuery pageQuery) {
        return terCleanOrderService.queryPageList(bo, pageQuery);
    }


    /**
     * 新增保洁记录
     */
    @RepeatSubmit()
    @PostMapping("/finishClean")
    public R<Void> add(@Validated(AddGroup.class) @RequestBody TerCleanerLogBo bo) {
        return toAjax(terCleanerLogService.insertByBo(bo));
    }

    /**
     * 订阅消息
     */
    @RepeatSubmit()
    @PostMapping("/subscription")
    public R<Void> subscription(@Validated(AddGroup.class) @RequestBody TerUserSubscriptionBo bo) {
        if(ObjectUtil.isNotEmpty(bo.getId())){
            toAjax(terUserSubscriptionService.updateByBo(bo));
        }else{
            toAjax(terUserSubscriptionService.insertByBo(bo));
        }
        return toAjax(true);
    }
}
